<template>
  <v-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible">
    <el-form style="overflow: hidden;" :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'" label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="地点" prop="venueName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.venueName" placeholder="请填写地点"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="时间段" prop="venueTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.venueTime" placeholder="请填写时间段"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请人" prop="userName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.userName" placeholder="请填写申请人"     ></el-input>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="申请时间" prop="createTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.createTime" placeholder="请填写申请时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="状态" prop="status"
                :rules="[
                 ]">
              <el-input v-model="inputForm.status" placeholder="请填写状态"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
        <el-row>
          <el-col >
            <el-form-item label="申请理由" prop="content"
                :rules="[
                 ]">
              <el-text class="mx-1" >{{ inputForm.content }}</el-text>
           </el-form-item>
        </el-col>
        <el-col v-if="inputForm.opinion">
            <el-form-item label="反馈" prop="opinion"
                :rules="[
                 ]">
              <el-text class="mx-1" >{{ inputForm.opinion }}</el-text>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <template #footer>    
        <span class="dialog-footer">
          <el-button @click="visible = false" icon="circle-close">关闭</el-button>
          <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button>
        </span>
    </template>    
  </v-dialog>
</template>

<script>
  import venuApplyService from '@/api/resource/venuApplyService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          time: '',
          status: ''
        }
      }
    },
    components: {
    },
    created () {
    },
    methods: {
      //查看
      view(val){
        console.log(val)
        this.method='view'
        this.title = '查看场地记录'
        this.visible = true
        this.loading = false
        this.inputForm=val
      },
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建场地记录`
        } else if (method === 'edit') {
          this.title = '修改场地记录'
        } else if (method === 'view') {
          this.title = '查看场地记录'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            venuApplyService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            venuApplyService.save(this.inputForm).then((data) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
<style scoped>
.mx-1{
  background-color: var(--el-disabled-bg-color);
  box-shadow: 0 0 0 1px var(--el-disabled-border-color) inset;
  border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
  padding: 1px 11px;
}
</style>
  
